<?php

namespace app\educational\service;
use app\classes\model\ClassModel;
use app\course\model\CourseModel;


class  FinancialService
{
    public function financialList($filter)
    {
        $where=[
            'c.delete_time' =>0,
            'cc.delete_time'=>0,
        ];
        $join=[

        ];
        $category=empty($filter['category'])?0:intval($filter['category']);
        array_push($join,[
            '__COURSE__ cc ', 'cc.id = c.course_id'
        ]);
        $field='c.*,cc.course_name ccname,cc.delete_time,cc.course_hour';
        $classModel=new ClassModel();
        if(!empty($filter['keyword']))
        {
            $where['cc.course_name']=['like',"%".trim($filter['keyword'])."%"];
        }
        $course=$classModel->alias('c')->field($field)
            ->join($join)
            ->where($where)
            ->order('update_time','DESC')
            ->order('id','DESC')
            ->paginate(10,false,['query' => $filter]);
        return $course;

    }
    //关联查询课程对应的课程表
    public function categroy()
    {
        $where=[
            'c.delete_time' =>0,
            'cc.delete_time' =>0,
        ];
        $join=[  '__COURSE_CATEGORY__ cc ', 'cc.id = c.category_id'];
        $course_model=new CourseModel();
        $field='c.*';
        $data=$course_model->alias('c')->field($field)
            ->join($join)
            ->where($where)
            ->select()
            ->toArray();
        return $data;
    }

}